package controllers

import (
	"encoding/json"
	"gitchina/kly_service/models"

	"github.com/astaxie/beego"
)

type GeneralController struct {
	beego.Controller
}

// @router /109001 [get]
func (g *GeneralController) GetDict() {
	var general models.General
	nc := general.GetDict(g.GetString("parent_id", ""))
	g.Data["json"] = models.NewOkResponse(nc)
	g.ServeJSON()
}

// @router /109002 [get]
func (g *GeneralController) GetParams() {
	var general models.General
	nc := general.GetParams(g.GetString("para_key", ""))
	g.Data["json"] = models.NewOkResponse(nc)
	g.ServeJSON()
}

// @router /109003 [get]
func (g *GeneralController) GetAdList() {
	var general models.General
	list := general.GetAdList()
	g.Data["json"] = models.NewOkResponse(list)
	g.ServeJSON()
}

// @router /109005 [post]
func (g *GeneralController) GetClientId() {
	var rq models.DeviceInfo
	var general models.General
	if err := json.Unmarshal(g.Ctx.Input.RequestBody, &rq); err == nil {
		profile := string(g.Ctx.Input.RequestBody)
		if clientId, err := general.GetClientId(rq, profile); err == nil {
			g.Data["json"] = models.NewOkResponse(clientId)
		} else {
			g.Data["json"] = models.NewFailResponse(err)
		}
		g.ServeJSON()
	} else {
		g.Ctx.ResponseWriter.WriteHeader(400)
	}
}

// @router /109006 [post]
func (g *GeneralController) AddClientErrorLogs() {
	var general models.General
	logs := string(g.Ctx.Input.RequestBody)
	general.AddClientErrorLog(logs)
	g.Data["json"] = models.NewOkResponse(nil)
	g.ServeJSON()
}

// @router /109007 [get]
func (g *GeneralController) GetBankList() {
	var general models.General
	list := general.GetBankList()
	g.Data["json"] = models.NewOkResponse(list)
	g.ServeJSON()
}

// @router /109008 [get]
func (g *GeneralController) GetDict2() {
	var general models.General
	nc := general.GetDict2(g.GetString("parent_id", ""))
	g.Data["json"] = models.NewOkResponse(nc)
	g.ServeJSON()
}
